package com.zph.three360panorama;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.zph.glpanorama.GLPanorama;
/**
 * Created by 張鵬輝 on 2017/8/29.
 *
 * E-mail: 1344670918@qq.com
 *
 * CSDN: http://blog.csdn.net/QingTianGG
 *
 * 有问题欢迎随时来找我共同解决
 */
public class OpenGLActivity extends AppCompatActivity {
    private GLPanorama mGLPanorama;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_open_gl);
        mGLPanorama= (GLPanorama) findViewById(R.id.mGLPanorama);
        //传入全景图片
        mGLPanorama.setGLPanorama(R.drawable.imggugong);

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(300, 300);
        params.setMargins(100, 200, 300, 300);

//        int imgSrc = (int)obj[2];   //获取图片资源id
        ImageView iv = new ImageView(this);
        iv.setImageResource(R.drawable.fresh);    //设置图片资源
        iv.setScaleType(ImageView.ScaleType.FIT_XY);   //拉伸图片到给定宽高
        mGLPanorama.addView(iv, params);


//        mGLPanorama.setOnTouchListener();

    }


    @Override
    public boolean onTouchEvent(MotionEvent e) {
        float y = e.getY();
        float x = e.getX();

        Log.e("onTouchEvent===", x+"==="+y);

//        switch (e.getAction()) {
//            case MotionEvent.ACTION_MOVE:
//                float dy = y - mPreviousY;// 计算触控笔Y位移
//                float dx = x - mPreviousX;// 计算触控笔X位移
//
//
//
//                mGLPanorama.mb.yAngle += dx * 0.3f;// 设置填充椭圆绕y轴旋转的角度
//
////			if(mBall.xAngle>=-360 && mBall.xAngle<=360){
////				mBall.xAngle += dy * 0.3f;// 设置填充椭圆绕x轴旋转的角度
////			}
//
//                if(mBall.xAngle + dy * 0.3f>=-50 && mBall.xAngle + dy * 0.3f<=50){
//                    mBall.xAngle += dy * 0.3f;// 设置填充椭圆绕x轴旋转的角度
//                }
//
//
//                Log.e("onTouchEvent===1", dx+"==="+dy+"==="+mPreviousX+"==="+mPreviousY+"==="+mBall.xAngle+"==="+mBall.yAngle);
//
//                Log.e("onTouchEvent===2", (mBall.xAngle%360/360*768)+"==="+(-mBall.yAngle%360/360*2100)+"==="+(mBall.xAngle%360/360*768+y*768/height)+"==="+(-mBall.yAngle%360/360*2100+x)+"==="+(mBall.xAngle%360/360*768+y*768/height)%768+"==="+(-mBall.yAngle%360/360*2100+2100/4*(1-Math.cos(Math.PI*x/width)))%2100+"==="+x*2100/width/2+"==="+Math.sin(Math.PI*x/width));
//        }
//        mPreviousY = y;// 记录触控笔位置
//        mPreviousX = x;// 记录触控笔位置
        return true;
    }

}
